package bean;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

/*
 * 貌似是J2ee的
 * 可以通过xml覆盖属性，支持hibernate validator和hibernate search
 * 1，标记对象bean
 *    @Entity
 *    @Table(name="")  
 *    @Table(name="tbl_sky",uniqueConstraints = {@UniqueConstraint(columnNames={"month", "day"})})
 *     乐观锁
 *     @Version
 *     @Column(name="OPTLOCK")
 * 
 * 2，标记简单属性
 *    @Transient 不加入到序列化中
 *    
 *    @Basic(fetch = FetchType.LAZY) 延迟加载 不同于lazy association fetching？
 * 
 *  
 *    @Lob
 *   
 * 3，列属性
 *    @Column( name="columnName"; (1)
 *    boolean unique() default false; (2)
 *    boolean nullable() default true; (3)
 *     boolean insertable() default true; (4)
 *     boolean updatable() default true; (5)
 *     String columnDefinition() default ""; (6)
 *     String table() default ""; (7)
 *     int length() default 255; (8)
 *     int precision() default 0; // decimal precision (9)
 *     int scale() default 0; // decimal scale
 *     
 *     @Embeddable
 *     @Embedded
 *     @AttributeOverrides( {
 *     @AttributeOverride(name="iso2", column = @Column(name="bornIso2") ),
 *     @AttributeOverride(name="name", column = @Column(name="bornCountryName") )
 *     } )
 *   
 *    Non-annotated property defaults
 *   If a property is not annotated, the following rules apply:
 *   If the property is of a single type, it is mapped as @Basic
 *   Otherwise, if the type of the property is annotated as @Embeddable, it is mapped as @Embedded
 *   Otherwise, if the type of the property is Serializable, it is mapped as @Basic in a column holding the object
 *   in its serialized version
 *   Otherwise, if the type of the property is java.sql.Clob or java.sql.Blob, it is mapped as @Lob with the appropriate
 *    LobType
 *    
 * 4，Id Mapping
 *    @Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SEQ_STORE")
 */

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.CascadeType;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "user")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class User implements Serializable {
	@Id
	@GeneratedValue(generator = "system-uuid")
	@GenericGenerator(name = "system-uuid", strategy = "uuid")
	private String id;
	private String name;
	private String ps;
	@Embedded
	private UserAbout UserAbout;
	@Column(columnDefinition = "Timestamp", nullable = false)
	@org.hibernate.annotations.Generated(org.hibernate.annotations.GenerationTime.INSERT)
	private Date joinTime;
	@OneToOne(cascade = CascadeType.ALL)
	@JoinTable(name = "useridcards", joinColumns = @JoinColumn(name = "user_fk"), inverseJoinColumns = @JoinColumn(name = "idcard_fk"))
	private IdCard idCard;
	@ManyToOne
	@JoinTable(name = "userworkfor", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "company_id"))
	// (cascade = {CascadeType.PERSIST,CascadeType.MERGE})
	private WorkCompany workCompany;

	/*
	 * 多对多关系
	 */
	@ManyToMany(targetEntity = School.class, cascade = { CascadeType.PERSIST,
			CascadeType.MERGE })
	@JoinTable(name = "user_school", joinColumns = @JoinColumn(name = "user_id"), inverseJoinColumns = @JoinColumn(name = "school_id"))
	private List<School> school;

	
	
	
	public WorkCompany getWorkCompany() {
		return workCompany;
	}

	public void setWorkCompany(WorkCompany workCompany) {
		this.workCompany = workCompany;
	}
	public IdCard getIdCard() {
		return idCard;
	}

	public void setIdCard(IdCard idCard) {
		this.idCard = idCard;
	}

	public List<School> getSchool() {
		return school;
	}

	public void setSchool(List<School> school) {
		this.school = school;
	}

	public Date getJoinTime() {
		return joinTime;
	}

	public void setJoinTime(Date joinTime) {
		this.joinTime = joinTime;
	}

	public String getId() {
		return id;
	}

	public UserAbout getUserAbout() {
		return UserAbout;
	}

	public void setUserAbout(UserAbout userAbout) {
		UserAbout = userAbout;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPs() {
		return ps;
	}

	public void setPs(String ps) {
		this.ps = ps;
	}

}
